package com.khotyn.heresy.validator;

import java.util.regex.Pattern;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.khotyn.heresy.bean.PicComment;

/**
 * 检测提交评论是内容是否规范
 * 
 * @author 黄挺
 * 
 */
public class AddCommentValidator implements Validator {

	@Override
	public boolean supports(Class arg0) {
		return PicComment.class.equals(arg0);
	}

	@Override
	public void validate(Object obj, Errors errors) {
		PicComment picComment = (PicComment) obj;

		// 为空检测
		if (Pattern.matches("^\\s{0,}$", picComment.getCommentContent())) {
			errors.rejectValue("picComment.commentContent",
					"commentContentNotNull", "您输入的内容不能为空");
		}

		// SQL注册检测
		if (Pattern.matches("", picComment.getCommentContent())) {
			errors.rejectValue("picComment.commentContent",
					"commentContentSQLInjection", "请不要输入关键字符或者SQL关键字");
		}
	}

}
